package com.cjy.common.utils.tag;

import com.cjy.common.utils.ApplicationUtils;
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.components.Component;
import org.apache.struts2.views.jsp.ui.AnchorTag;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 封装的A自定义权限控制标签，主要用于按钮的控制
 * User: jay.zhoujingjie
 * Date: 13-12-20
 * Time: 下午1:15
 */
public class ATag extends AnchorTag
{
	private static final long	serialVersionUID	= 1L;
	//权限键值
    private String authKey;

    public String getAuthKey()
	{
		return authKey;
	}

	/**
	 * 获取标签Bean
	 * @see org.apache.struts2.views.jsp.ui.AnchorTag#getBean(com.opensymphony.xwork2.util.ValueStack, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
    public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res)
    {
        return new ATagBean(stack,req,res);
    }

	/**
     * 拼装参数
     * @see org.apache.struts2.views.jsp.ui.AnchorTag#populateParams()
     */
    @Override
    protected void populateParams()
    {
        super.populateParams();
        ATagBean a = (ATagBean) getComponent();
        a.setVisible(ApplicationUtils.isAllowAsThisAction(authKey));
    }

    public void setAuthKey(String authKey)
	{
		this.authKey = authKey;
	}
}
